﻿using System;
using System.IO;

namespace Microsoft.WowAddonStudio.TocEditor
{
    public class FileRepresentation : IFileRepresentation
    {
    	/// <summary>
		/// Initializes a new instance of the <see cref="FileRepresentation"/> class.
		/// </summary>
		/// <param name="relativePath">The relative path.</param>
		/// <param name="isIncluded">if set to <c>true</c> [is included].</param>
        public FileRepresentation(string relativePath, bool isIncluded)
        {
            CheckRelativePath(relativePath);
            this.RelativePath = relativePath;
            this.IsIncluded = isIncluded;
        }

		/// <summary>
		/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
		/// </summary>
		/// <returns>
		/// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
		/// </returns>
        public override string ToString()
        {
            return RelativePath;
        }

        #region IFileRepresentation Members

		/// <summary>
		/// Gets or sets a value indicating whether this instance is included.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is included; otherwise, <c>false</c>.
		/// </value>
    	public bool IsIncluded { get; set; }

    	/// <summary>
    	/// Gets the relative path.
    	/// </summary>
    	/// <value>The relative path.</value>
    	public string RelativePath { get; private set; }

    	#endregion

		/// <summary>
		/// Checks the relative path.
		/// </summary>
		/// <param name="relativePath">The relative path.</param>
        private static void CheckRelativePath(string relativePath)
        {
            if (relativePath == null)
                throw new ArgumentNullException("relativePath");

            if (string.IsNullOrEmpty(Path.GetFileName(relativePath)))
                throw new ArgumentException("Relative path does not represent a file.", "relativePath");
        }
    }
}
